#!/usr/bin/python3

import os
import sys
import shutil
import wstage4
import subprocess

dp = {
    "rtl8139": "rtl8139c.zip"
}
if True:
    installMedia = wstage4.os_win98.LocalInstallationMedia("/var/cache/mirrors/oldwin/storage-file/windows-98-se-oem.en-us.iso",
                                                           None,
                                                           "bios.bin",
                                                           "patcher9x-0.8.50-boot.ima",
                                                           driverpack_filepath_dict=dp)
else:
    installMedia = wstage4.os_win98.LocalInstallationMedia("/var/cache/mirrors/oldwin/storage-file/windows-98-se.en-us.iso",
                                                           "/var/cache/mirrors/oldwin/storage-file/Windows_98_Second_Edition_Boot.img",
                                                           "bios.bin",
                                                           "patcher9x-0.8.50-boot.ima",
                                                           driverpack_filepath_dict=dp)

os.makedirs("./t", exist_ok=True)
subprocess.check_call("rm -rf ./t/*", shell=True)
wdir = wstage4.WorkDir("./t", reset=True)

s = wstage4.Settings()
s.program_name = "test"
s.verbose_level = 1

ts = wstage4.os_win98.TargetSettings()
ts.arch = wstage4.Arch.X86
ts.version = wstage4.Version.WINDOWS_98
ts.edition = wstage4.Edition.WINDOWS_98_SE
ts.lang = wstage4.Lang.en_US
#ts.product_key = "DTXM2-YVDH9-JHYV2-MPCJH-CCRFH"        # do not commit
ts.product_key = "PJGVK-PV9FF-VCYYM-643MJ-WTGFW"        # do not commit
ts.user_name = "fpemud"
ts.timezone = "GMT"
ts.keyboard_layout = "United State 101"
ts.locale = "English (United States)"
# ts.optional_components_blacklisted = wstage4.os_win98.Spec().getOptionalComponentList()
# ts.optional_desktop_icons_blacklisted = wstage4.os_win98.Spec().getOptionalDesktopIconList()
ts.extra_drivers = list(dp.keys())

with wstage4.Builder(s, ts, wdir) as builder:
    print("        - Prepare...")
    builder.action_prepare(installMedia)

    print("        - Installing windows...")
    builder.action_install_os()

    print("        - Installing core applications...")
    builder.action_install_applications()

    print("        - Cleaning up...")
    builder.action_cleanup()

    print("        - Finish...")
    builder.finish()
